package exercise4;
import java.math.BigDecimal;

import javax.swing.JOptionPane;;
public class NumberOfPlus {
	public static int sumDigits(long n){
        String inputString = String.valueOf(n);
        BigDecimal bigDecimal = new BigDecimal(inputString);//BigDecimal可以精确计算
        String string = bigDecimal.toString();
        char[] charArray = string.toCharArray();
        StringBuffer buffer = new StringBuffer();//与String相似，但是StringBuffer对象能多次被修改
        // 从个位数
        int sum=0;
        for (int i = charArray.length - 1; i >= 0; i--)
        {
            buffer.append(charArray[i] + " ");//append在对象后面追加字符串
            sum+=charArray[i]-'0';
        }
        return sum;
	}
}
